package com.tanhua.server.service;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.dubbo.config.annotation.Reference;
import com.tanhua.dubbo.server.api.RecommendUserApi;
import com.tanhua.dubbo.server.pojo.RecommendUser;
import com.tanhua.server.vo.TodayBest;
import org.springframework.stereotype.Service;

/**
 * @program: my-tanhua
 * @description:
 * @author: xuejingjing
 * @create: 2021-09-21 13:22
 **/

//负责与dubbo的服务交互
@Service
public class RecommendUserService {

    @Reference(version =  "1.0.0")
    private RecommendUserApi recommendUserApi;

    public TodayBest queryTodayBest(Long id) {
        RecommendUser recommendUser = recommendUserApi.queryWithMaxScore(id);
        if(null ==recommendUser){
            return null;
        }
        TodayBest todayBest = new TodayBest();
        todayBest.setId(recommendUser.getUserId());
        //缘分值
        double score = Math.floor(recommendUser.getScore());
        todayBest.setFateValue(Double.valueOf(score).longValue());
        return todayBest;
    }


    public void queryCommendUserList(Long userId,Integer page,Integer pageSize) {
//        调用dubbo的服务查询
        recommendUserApi.queryPageInfo(userId, page, pageSize);
    }

    public Double queryScore(Long userId,Long toUserId){
        Double aDouble = recommendUserApi.queryScore(userId, toUserId);
        if(ObjectUtil.isNotEmpty(aDouble)){
            return aDouble;
        }
        //默认值
         return 98d;
    }
}